<?php
// 登录接口
include_once 'conn.php';
$user=$_POST['user'];
$pass=$_POST['pass'];
$date=time();//获取当前时间戳
$token=md5($user.$pass.$date);
$sql=$db->query("SELECT user_name FROM user WHERE user_name = '$user' AND user_pass = '$pass'");
if ($sql -> num_rows > 0) {
    // 登录时客户端没有token，通知服务器更新新的token
    // $db->query(""),然后把新的token返回客户端
    $db->query("UPDATE user SET user_token = '$token',user_update_time = '$date' WHERE user_name = '$user' AND user_pass = '$pass'");
    echo json_encode(["token"=>$token]);
}else{
    echo json_encode(['exist'=>false]);
}
$db -> close();
?>